package com.ark.cloud.javacallnative.modules.storage.service.impl;

import com.alibaba.fastjson.JSON;
import com.ark.cloud.javacallnative.entity.ReconnoiterCmd;
import com.ark.cloud.javacallnative.entity.ReconnoiterCmdVecThreed;
import com.ark.cloud.javacallnative.entity.Vec3D;
import com.ark.cloud.javacallnative.modules.storage.mapper.ReconnoiterCmdMapper;
import com.ark.cloud.javacallnative.modules.storage.mapper.ReconnoiterCmdVecThreedMapper;
import com.ark.cloud.javacallnative.modules.storage.mapper.Vec3DMapper;
import com.ark.cloud.javacallnative.modules.storage.service.ReconnoiterCmdSerivce;
import com.ark.cloud.javacallnative.util.UUIDUtil;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

@Service
@Slf4j

public class ReconnoiterCmdSerivceImpl extends ServiceImpl<ReconnoiterCmdMapper, ReconnoiterCmd> implements ReconnoiterCmdSerivce {


    @Resource
    private ReconnoiterCmdMapper reconnoiterCmdMapper;

    @Resource
    private Vec3DMapper vec3DMapper;

    @Resource
    private ReconnoiterCmdVecThreedMapper reconnoiterCmdVecThreedMapper;


    @Override
    public void saveReconnoiterCmd(ReconnoiterCmd reconnoiterCmd) {

        reconnoiterCmd.setId(UUIDUtil.next());

        System.out.println("reconnoiterCmd: {}"+ JSON.toJSONString(reconnoiterCmd));
        reconnoiterCmdMapper.saveReconnoiterCmd(reconnoiterCmd);

        System.out.println("添加后 reconnoiterCmd: {}"+ JSON.toJSONString(reconnoiterCmd));
        Long reconnoiterCmdId = reconnoiterCmd.getId();

        ArrayList<Vec3D> areaList = reconnoiterCmd.getAreaList();

        for(Vec3D vec3D : areaList){

            vec3D.setId(UUIDUtil.next());
            System.out.println("vec3D:"+vec3D);

            vec3DMapper.insert(vec3D);

            Long vec3DId = vec3D.getId();

//            添加到中间表
            ReconnoiterCmdVecThreed reconnoiterCmdVecThreed = new ReconnoiterCmdVecThreed();

            reconnoiterCmdVecThreed.setId(UUIDUtil.next());
            reconnoiterCmdVecThreed.setReconnoiterCmdId(reconnoiterCmdId);
            reconnoiterCmdVecThreed.setVecThreedId(vec3DId);

            log.info("reconnoiterCmdVecThreed: {}", JSON.toJSONString(reconnoiterCmdVecThreed));

            int insert = reconnoiterCmdVecThreedMapper.insert(reconnoiterCmdVecThreed);
            System.out.println("insert:"+insert);


        }



    }

}
